﻿using Abp.Application.Services.Dto;
using Abp.Runtime.Validation;
using System.ComponentModel.DataAnnotations;
using WebApiClient.DataAnnotations;

namespace NetCore.Dtos
{
    public class PagedInputDto : BaseDto, IPagedResultRequest
    {
        public PagedInputDto()
        {
            MaxResultCount = AppConsts.DefaultPageSize;
            SkipCount = PageIndex * MaxResultCount ?? SkipCount;
            Sorting = $"{nameof(CreationTime)} desc";
        }

        ///// <summary>
        ///// 每页数据量 用MaxResultCount 代替
        ///// </summary>
        //public int? PageSize { get; set; }

        [Range(1, AppConsts.MaxPageSize), AliasAs("maxResultCount")]
        public int MaxResultCount { get; set; }

        [Range(0, int.MaxValue), AliasAs("skipCount")]
        public int SkipCount { get; set; }

        /// <summary>
        /// 传递页码后影响SkipCount的值
        /// </summary>
        [AliasAs("pageIndex")]
        public int? PageIndex { get; set; }
        /// <summary>
        /// 提供给前端传递字符串或者json字符串的数据过滤对象，后端可以直接获取或者反序列化为需要的对象
        /// </summary>
        [AliasAs("filter")]
        public string Filter { get; set; }
        /// <summary>
        /// 格式："CreationTime DESC, LastModificationTime DESC" Or "CreationTime, LastModificationTime" 
        /// </summary>
        [AliasAs("sorting")]
        public string Sorting { get; set; }

        public override void AddValidationErrors(CustomValidationContext context)
        {
            //if (!Phone.Validate())
            //{
            //    context.Results.Add(new ValidationResult("请输入正确的电话号码!"));
            //}
            //if (Files.Count > 20)
            //{
            //    context.Results.Add(new ValidationResult("批量上传文件最多20个"));
            //}

            //base.AddValidationErrors(context);
        }
    }
}
